package pl.edu.pw.polygen.modeler.client.object.listener;

import pl.edu.pw.polygen.modeler.client.object.IPolygenObject;
import pl.edu.pw.polygen.modeler.client.workspace.IWorkspace;

import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseUpEvent;

public class SelectableVertexListener extends BaseObjectListener {

	
	@Override
	public void onMouseDown(MouseDownEvent event, IPolygenObject polygenObject) {
		IWorkspace context = polygenObject.getContext();
		context.setMouseDownCatch(true);
		if(polygenObject.isSelected()==false){
			context.unselectAll();
			polygenObject.hold();
			context.showProperties(polygenObject);
		}else{
			context.catchMouseClickedPosition();
			context.setMoveable(true);
		}
	}

	@Override
	public void onMouseUp(MouseUpEvent event, IPolygenObject polygenObject) {
		if(polygenObject.isHolded()==true){
			polygenObject.drop();
			polygenObject.select();
		}
		polygenObject.getContext().setMoveable(false);
	}

		@Override
	public void onMouseOver(MouseOverEvent event, IPolygenObject polygenObject) {
		if(polygenObject.isSelected()==false && polygenObject.isHolded()==false){
			polygenObject.over();
		}
	}

	@Override
	public void onMouseOut(MouseOutEvent event, IPolygenObject polygenObject) {
		if(polygenObject.isSelected()==false && polygenObject.isHolded()==false){
			polygenObject.out();
		}
	}

}
